package com.pxene.dmp.task;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;

import com.pxene.dmp.common.DateUtils;
import com.pxene.dmp.constant.BaseConstant;
import com.pxene.dmp.constant.FileSuffixTime;

public class RemoveDataTask implements Tasklet {
	@Autowired
	private FileSystem hadoopFs;

	@Override
	public RepeatStatus execute(StepContribution contribution,
			ChunkContext context) throws Exception {
		// 删除本小时所跑数据时间前8小时的数据
		String date = DateUtils.getFormat(
				DateUtils.addHours(DateUtils.getDate(
						FileSuffixTime.getDatehour(), "yyyyMMddHH"), -8),
				"yyyyMMddHH");

		Path path = new Path(BaseConstant.HDFS_TEMP_ROOT_DIR + date + "/");
		if (hadoopFs.exists(path)) {
			hadoopFs.delete(path, true);
		}

		return RepeatStatus.FINISHED;
	}

}
